<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>{{artifactId}}</artifactId>
        <groupId>{{groupId}}</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>{{artifactId}}-server</artifactId>

    <name>{{artifactId}}-server</name>
    <url>http://{{domainName}}</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>{{groupId}}</groupId>
            <artifactId>{{artifactId}}-api</artifactId>
        </dependency>
        <dependency>
            <groupId>{{groupId}}</groupId>
            <artifactId>{{artifactId}}-common</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fireflysource</groupId>
            <artifactId>firefly-kotlin-ext</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fireflysource</groupId>
            <artifactId>firefly-slf4j</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fireflysource</groupId>
            <artifactId>firefly-session</artifactId>
        </dependency>

        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>

    <build>
        <finalName>{{artifactId}}-server</finalName>
        <defaultGoal>install</defaultGoal>
        <filters>
            <filter>${env}</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/static_resources</directory>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/*.xml</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>${resource.directory}</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <filtering>true</filtering>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>{{packageName}}.server.AppKt</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <finalName>{{artifactId}}-server</finalName>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <copy file="${project.build.directory}/{{artifactId}}-server-jar-with-dependencies.jar"
                                      tofile="${project.build.directory}/${package.name}.jar"/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <configuration>
                    <compilerPlugins>
                        <!-- Or "jpa" for JPA support -->
                        <plugin>no-arg</plugin>
                        <plugin>all-open</plugin>
                    </compilerPlugins>

                    <pluginOptions>
                        <option>no-arg:annotation=com.firefly.kotlin.ext.annotation.NoArg</option>
                        <option>no-arg:annotation=com.firefly.annotation.Component</option>
                        <option>no-arg:annotation=com.firefly.annotation.Proxies</option>
                        <option>no-arg:annotation=com.firefly.annotation.Proxy</option>
                        <option>no-arg:annotation=com.firefly.db.annotation.Table</option>

                        <option>all-open:annotation=com.firefly.annotation.Component</option>
                        <option>all-open:annotation=com.firefly.annotation.Proxies</option>
                        <option>all-open:annotation=com.firefly.annotation.Proxy</option>
                        <option>all-open:annotation=com.firefly.db.annotation.Table</option>
                    </pluginOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>compile</id>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>${project.basedir}/src/main/java</sourceDir>
                                <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>${project.basedir}/src/test/java</sourceDir>
                                <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>

                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-noarg</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerArgument>-parameters</compilerArgument>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <!-- Replacing default-compile as it is treated specially by maven -->
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                    <!-- Replacing default-testCompile as it is treated specially by maven -->
                    <execution>
                        <id>default-testCompile</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>java-compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>java-test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <env>src/main/filters/local/env.properties</env>
                <resource.directory>src/main/config/local</resource.directory>
                <package.name>test-{{uberJarName}}</package.name>
            </properties>
        </profile>
        <profile>
            <id>rd</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <env>src/main/filters/rd/env.properties</env>
                <resource.directory>src/main/config/rd</resource.directory>
                <package.name>test-{{uberJarName}}</package.name>
            </properties>
        </profile>
        <profile>
            <id>beta</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <env>src/main/filters/beta/env.properties</env>
                <resource.directory>src/main/config/beta</resource.directory>
                <package.name>beta-{{uberJarName}}</package.name>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <env>src/main/filters/prod/env.properties</env>
                <resource.directory>src/main/config/prod</resource.directory>
                <package.name>{{uberJarName}}</package.name>
            </properties>
        </profile>
    </profiles>
</project>
